package us.icitap.cm.business.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="EVIDENCE", schema="MPC")
@TableGenerator(name="EVIDENCE_IDS",table="AUTO_IDS",valueColumnName="LAST_ID",initialValue=1, allocationSize=1,schema="MPC")
public class Evidence implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4417190642946850330L;

	public enum EvidenceTypeEnum{
		TESTIMONY("Deshmi"),
		INTERROGATION("Marrje ne pyetje"),
		CONFRONTATION("Ballafaqim"),
		RECOGNITION("Njohje"),
		EXPERIMENT("Eksperiment"),
		EXPERTISE("Ekspertim"),
		MATERIAL("Prove materiale"),
		VIRTUAL("Prove virtuale");
		
		private String caption;
		private EvidenceTypeEnum(String caption){
			this.caption = caption;
		}
		
		public String getCaption(){
			return this.caption;
		}
		
		public String toString(){
			return caption;
		}
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="EVIDENCE_IDS")
	private Integer id;
	
	@Column(name="EVIDENCE_NO", length=15)
	private String evidenceNo;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="EVIDENCE_DATE")
	private Date evidenceDate;
	
	@Enumerated(EnumType.STRING)
	@Column(name="EVIDENCE_TYPE", length=20)
	private EvidenceTypeEnum evidenceType;
	
	@ManyToOne
	@JoinColumn(name="EVIDENCE_ID_METHOD_ID")
	private AppList evidenceIdentMethod;

	@ManyToOne
	@JoinColumn(name="HISTORY_EVIDENCE_ID")
	private Evidence historyEvidence;
	
	@Column(length=300)
	private String notes;
	
	public Evidence() {
		
	}

	public Evidence(Evidence evidence) {
		this.evidenceNo = evidence.getEvidenceNo();

		this.evidenceDate = evidence.getEvidenceDate();
		this.evidenceType = evidence.getEvidenceType();
		this.evidenceIdentMethod = evidence.getEvidenceIdentMethod();
		this.notes = evidence.getNotes();
		this.historyEvidence = evidence;
	}

	
	

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getEvidenceNo() {
		return evidenceNo;
	}

	public void setEvidenceNo(String evidenceNo) {
		this.evidenceNo = evidenceNo;
	}

	public Date getEvidenceDate() {
		return evidenceDate;
	}

	public void setEvidenceDate(Date evidenceDate) {
		this.evidenceDate = evidenceDate;
	}

	public EvidenceTypeEnum getEvidenceType() {
		return evidenceType;
	}

	public void setEvidenceType(EvidenceTypeEnum evidenceType) {
		this.evidenceType = evidenceType;
	}

	public AppList getEvidenceIdentMethod() {
		return evidenceIdentMethod;
	}

	public void setEvidenceIdentMethod(AppList evidenceIdentMethod) {
		this.evidenceIdentMethod = evidenceIdentMethod;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		
		result = prime * result
				+ ((evidenceDate == null) ? 0 : evidenceDate.hashCode());
		result = prime
				* result
				+ ((evidenceIdentMethod == null) ? 0 : evidenceIdentMethod
						.hashCode());
		result = prime * result
				+ ((evidenceNo == null) ? 0 : evidenceNo.hashCode());
		result = prime * result
				+ ((evidenceType == null) ? 0 : evidenceType.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((notes == null) ? 0 : notes.hashCode());
//		result = prime
//				* result
//				+ ((subjectAppEntity == null) ? 0 : subjectAppEntity.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Evidence other = (Evidence) obj;
		
		if (evidenceDate == null) {
			if (other.evidenceDate != null)
				return false;
		} else if (!evidenceDate.equals(other.evidenceDate))
			return false;
		if (evidenceIdentMethod == null) {
			if (other.evidenceIdentMethod != null)
				return false;
		} else if (!evidenceIdentMethod.equals(other.evidenceIdentMethod))
			return false;
		if (evidenceNo == null) {
			if (other.evidenceNo != null)
				return false;
		} else if (!evidenceNo.equals(other.evidenceNo))
			return false;
		if (evidenceType != other.evidenceType)
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
	
		return true;
	}

	
	public boolean myEquals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Evidence other = (Evidence) obj;
		
		if (evidenceDate == null) {
			if (other.evidenceDate != null)
				return false;
		} else if (!evidenceDate.equals(other.evidenceDate))
			return false;
		if (evidenceIdentMethod == null) {
			if (other.evidenceIdentMethod != null)
				return false;
		} else if (!evidenceIdentMethod.equals(other.evidenceIdentMethod))
			return false;
		if (evidenceNo == null) {
			if (other.evidenceNo != null)
				return false;
		} else if (!evidenceNo.equals(other.evidenceNo))
			return false;
		if (evidenceType != other.evidenceType)
			return false;
		
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		
		return true;
	}


	@Override
	public String toString() {
		return this.evidenceNo + ", " + this.evidenceType.getCaption();
	}

	public String toFullString() {
		return "[PROVE] " + this.evidenceType.getCaption() + ", " + this.evidenceNo;
	}


	public Evidence getHistoryEvidence() {
		return historyEvidence;
	}




	public void setHistoryEvidence(Evidence historyEvidence) {
		this.historyEvidence = historyEvidence;
	}



	
}
